package com.mjw.zstu.controller;

import com.mjw.zstu.resultDto.JsonResult;
import com.mjw.zstu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mjw.zstu.entity.Orderlist;
@RestController
@CrossOrigin
@RequestMapping("order")
public class OrderController {
    @Autowired
    OrderService orderService;
    //卖家
    @RequestMapping("companylist")
    public JsonResult getCompanyOrder(int company_id,int status){
        return orderService.getOrderList(company_id,status);
    }
    //买家
    @RequestMapping("list")
    public JsonResult getUserCompanyList(int id,boolean is_company,int status){
        if(is_company){
          return   orderService.getbuyerCompany(id,status);
        }
        return orderService.getbuyerUser(id,status);
    }
    //下单
    @RequestMapping("buy")
    public JsonResult buy(@RequestBody Orderlist orderlist){
      return  orderService.create(orderlist);
    }
    //详情
    @RequestMapping("detail")
    public JsonResult detail(int id){
        return orderService.detail(id);
    }
    @RequestMapping("quit")
    public JsonResult quit(@RequestBody Orderlist order){
        return orderService.quit(order.getId(),order.getReason());
    }
    @RequestMapping("track")
    public JsonResult track(@RequestBody Orderlist orderlist){
        return orderService.fahuo(orderlist.getId(),orderlist.getTrack_number(),orderlist.getTrack_name());
    }
    @RequestMapping("confirmquit")
    public JsonResult confirm(int id){
        return orderService.confirm(id);
    }
    @RequestMapping("shouhuo")
    public JsonResult shouhuo(int id){
        return orderService.shouhuo(id);
    }
    @RequestMapping("evaluate")
    public JsonResult evaluate(@RequestBody Orderlist orderlist){
        return orderService.star(orderlist.getId(),orderlist.getStar(),orderlist.getEvaluate());
    }
    @RequestMapping("all_list")
    public JsonResult all_list(int status){
        return orderService.getalllist(status);
    }
//    @RequestMapping("sell")
//    public JsonResult getSell(int company_id,int status){
//        return orderService.getSellerOrder(company_id, status);
//    }
}
